package com.ak.routeTopic;

import com.ak.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.Random;

public class Provider {
    public static void main(String[] args) throws IOException {
        Connection connection= RabbitMQUtils.getConnection();
        Channel channel=connection.createChannel();
        // 参数一：为交换机名称，参数二：fanout 为交换机
        String channelName="log_top";
        channel.exchangeDeclare(channelName,"topic");
        String []routeKey={"user.save","user.add","admin.add","admin.save"};

        for (int i=0;i<10;i++){
            int temp=new Random().nextInt(100)%4;
            channel.basicPublish(channelName,routeKey[temp],null,("这个是topics 发布的信息"+routeKey[temp]).getBytes());
        }
        RabbitMQUtils.closeConnectionAndChanel(channel,connection);
    }
}
